The present invention relates to methods and apparatus for calculating jump addresses in a microprocessor.
Before a jump to another location can be done, the instruction must be first decoded to determine that it is a jump instruction. A jump instruction will contain a displacement value, which may be one or more bytes. The instruction must be decoded to determine the number of bytes which belong to the displacement value. This displacement value is then added to the current instruction address to determine the location of the instruction being jumped to. The current instruction address is stored in a program counter register. In addition, the length of the instruction itself must be added to the jump address. This is because the program counter points to the beginning of the instruction, and a displacement indicates a value from the end of the instruction, so that the length of the instruction must be added to bridge the gap.
A jump may also be unconditional or conditional. If it is unconditional, it will always be taken. If it is conditional, an operation designated by the instruction must be first performed to determine whether the jump is to be taken. This is typically done in an execution stage of the microprocessor logic following the decoding stage.
Finally, the calculated jump address must be converted into a physical address. In some systems, the memory may be segmented so that a constant value indicating the segment must be added to the address. This is often called a virtual (or effective) address to linear address conversion. In addition, the memory system may use paging, which would further break up the segments of memory. Certain high order bits designate the page, and must be translated into the actual physical address in order to fetch the instruction from memory. The address after the segmentation calculation and before the paging calculation is sometimes called a linear address, an intermediate address between the virtual and physical addresses.
In some programs, approximately 25% of the instructions may be jump instructions. These jump instructions may take as many as nine cycles for execution. Accordingly, it is desirable to reduce the number of cycles required to execute a jump in order to increase the speed of processing.